package test3;

import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

//单个监听器
public class Login extends JFrame implements ActionListener {
    JPasswordField p;
    JTextField t;
    Write write;

    //为了再监听方法中能用到该值,所以将其定义为属性
    public Login() {
        setBounds(1000, 100, 400, 200);
        Font f1 = new Font("隶书", Font.BOLD + Font.BOLD, 20);
        setLayout(new GridLayout(3, 1));
        JPanel p1 = new JPanel();
        JLabel l1 = new JLabel("账号");
        l1.setFont(f1);
        t = new JTextField(20);
        p1.add(l1);
        p1.add(t);

        JPanel p2 = new JPanel();
        JLabel l2 = new JLabel("密码");
        l2.setFont(f1);
        p = new JPasswordField(20);
        p2.add(l2);
        p2.add(p);

        JPanel p3 = new JPanel();
        JButton b = new JButton("登陆");
        b.addActionListener(this);
        p3.add(b);

        add(p1);
        add(p2);
        add(p3);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
        new Login();
    }

    public void actionPerformed(ActionEvent arg0) {
        if (t.getText().equals("") || p.getText().equals("") || t.getText().equals(null) || p.getText().equals(null)) {
            JOptionPane.showMessageDialog(null, "输入不能为空");
        } else {
            for (int i = 1; i <= 52; i++) {
                if (t.getText().equals("" + i)) {
                    if (p.getText().equals("" + i)) {
                        new LoginSelect();
                        write = new Write(t.getText() + "/", "src/log.txt");
                    }
                }
            }
            if (t.getText().equals("root")) {
                if (p.getText().equals("root")) {
                    new Administrator();
                }
            }
        }

    }

}

